<template>
  <div class="backDiv">
    <!--    面包屑导航区域-->
    <el-card style="width: 70%;margin-top: 30px;">
      <el-breadcrumb separator-class="el-icon-arrow-right" style="margin-bottom: 30px;">
        <el-breadcrumb-item :to="{ path: '/header' }">首页</el-breadcrumb-item>
      </el-breadcrumb>
      <el-table
        :data="discountslist"
        style="width: 100%;margin-top: 30px;margin-bottom: 20px"
        border
        stripe>
        <!-- 添加索引列 直接把type属性设置成index即可-->
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="disName" label="组合套餐名称">
        </el-table-column>
        <el-table-column prop="disGoods" label="组合商品列表"></el-table-column>
        <el-table-column prop="disDiscount" label="折扣"></el-table-column>
      </el-table>
      <!--      分页区域-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'DiscountsList',
  data () {
    return {
      discountslist: [],
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 2
      },
      total: 0
    }
  },
  created () {
    this.getDiscountsList()
  },
  methods: {
    // 监听每页显示数量变化函数
    handleSizeChange (newSize) {
      console.log(newSize)
      this.queryInfo.pagesize = newSize
      // 每页显示数量变化后 重新请求用户列表
      this.getDiscountsList()
    },
    // 监听当前页码变化函数
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getDiscountsList()
    },
    getDiscountsList () {
      this.$axios.get('discounts', {params: this.queryInfo})
        .then(resp => {
          if (resp && resp.data.status !== 200) {
            return this.$message.error('获取商品组合优惠列表失败!')
          }
          this.discountslist = resp.data.data.data
          this.total = resp.data.data.totalpage
          console.log(resp.data.data)
          this.$message.success('获取商品组合优惠列表成功!')
        })
    }
  }
}
</script>

<style scoped>
.backDiv {
  width: 100%;
  background-repeat: repeat;
  display: flex;
  justify-content: center;
  align-items:center;
  flex-flow: column;
}
</style>
